package com.zhangzhan.controller;

import com.zhangzhan.domain.commcon.ResponseResult;
import com.zhangzhan.domain.dto.AddArticleDto;
import com.zhangzhan.domain.dto.LikeArticleDto;
import com.zhangzhan.domain.dto.UpdateArticleDto;
import com.zhangzhan.domain.vo.PageVO;
import com.zhangzhan.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张一恒
 * @version 1.0
 * @description:
 * @date 2022/12/6 16:55
 */
@RestController
@RequestMapping("/content/article")
public class AdminArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * @description 新增博文
     * @param addArticleDto
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 9:41
     */
    @PostMapping
    public ResponseResult addArticle(@RequestBody AddArticleDto addArticleDto){
        return articleService.addArticle(addArticleDto);
    }


    /**
     * @description 分页查找博文
     * @param pageNum
     * @param pageSize
     * @param likeArticleDto
     * @return com.zhangzhan.domain.commcon.ResponseResult<com.zhangzhan.domain.vo.PageVO>
     * @author 31115
     * @date 2022/12/7 9:59
     */
    @GetMapping("/list")
    public ResponseResult<PageVO> listArticle(Integer pageNum, Integer pageSize, LikeArticleDto likeArticleDto){
        return articleService.listArticle(pageNum,pageSize,likeArticleDto);
    }

    /**
     * @description 修改回显数据
     *
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 10:02
     */
    @GetMapping("{id}")
    public ResponseResult select(@PathVariable Long id){
        return articleService.select(id);
    }

    /**
     * @description 修改文章接口
     * @param updateArticleDto
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 10:37
     */
    @PutMapping
    public ResponseResult update(@RequestBody UpdateArticleDto updateArticleDto){
        return articleService.updateArticle(updateArticleDto);
    }

    /**
     * @description 逻辑删除博文
     * @param id
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/7 10:58
     */
    @DeleteMapping("{id}")
    public ResponseResult deleteArticle(@PathVariable Long id){
        return articleService.deleteArticle(id);
    }


}
